﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PosHacker;


namespace Nissen_Manage.Forms
{
	public partial class PasswordChangeManage : Form
	{
		public Form MainForm { get; set; }

		public PasswordChangeManage()
		{
			InitializeComponent();
		}

		private void btnSubmit_Click(object sender, EventArgs e)
		{

            //POSHacker _posHacker = POSHacker.GetInstance("Ge0201", "Pa66word");

            //_posHacker.Login();

            //_posHacker.ChangPassword("Pa66word","Test1!@#");

            //return;


			try
			{
				if (CheckPwd())
				{

					PasswordChangeService passwordChangeService = new PasswordChangeService();

					//passwordChangeService.ChangePassword(this.txtPwdOne.Text);
				    IList<string> _list =
				        passwordChangeService.ChangePasswordOnebyOne(this.txtPwdOne.Text);
                    if(_list.Count == 0)
					    MessageBox.Show("保存成功！");
                    else
                    {
                        string str = "";
                        foreach (var item in _list)
                        {
                            str += "\n";
                            str += item;
                        }
                        MessageBox.Show("下列帐号修改失败！"+str);
                    }
				}
			}
			catch (Exception ex)
			{

				MessageBox.Show(ex.Message);
			}

			
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		private void PasswordChangeManage_FormClosed(object sender, FormClosedEventArgs e)
		{
			MainForm.Show();
		}

		private bool CheckPwd()
		{
			string pwdOne = this.txtPwdOne.Text;
			string pwdTwo = this.txtPwdTwo.Text;

			if(string.IsNullOrEmpty(pwdOne) ||string.IsNullOrEmpty(pwdTwo))
			{
				MessageBox.Show("新密码不能为空！");
				return false;
			}
			if(pwdOne!=pwdTwo)
			{
				MessageBox.Show("密码不一致！");
				return false;
			}
            if (pwdOne.Length<8 || pwdTwo.Length<8)
            {
                MessageBox.Show("长度小于8！");
                return false;
            }
		    return true;
		}

	}
}
